package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightOrderChangeTickets;
import com.ktgj.flight.service.IFlightOrderChangeTicketsService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票预订_机票退改签订单机票信息Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/tickets")
public class FlightOrderChangeTicketsController extends BaseController
{
    @Autowired
    private IFlightOrderChangeTicketsService flightOrderChangeTicketsService;

    /**
     * 查询机票预订_机票退改签订单机票信息列表
     */
    @PreAuthorize(hasPermi = "flight:tickets:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightOrderChangeTickets flightOrderChangeTickets)
    {
        startPage();
        List<FlightOrderChangeTickets> list = flightOrderChangeTicketsService.selectFlightOrderChangeTicketsList(flightOrderChangeTickets);
        return getDataTable(list);
    }

    /**
     * 查询机票预订_机票退改签订单机票信息列表
     * @param flightOrderChangeTickets
     * @return
     */
    @PostMapping("/orderChangeTicketsList")
    public List<FlightOrderChangeTickets> orderChangeTicketsList(FlightOrderChangeTickets flightOrderChangeTickets) {
        List<FlightOrderChangeTickets> list = flightOrderChangeTicketsService.selectFlightOrderChangeTicketsList(flightOrderChangeTickets);
        return list;
    }

    /**
     * 导出机票预订_机票退改签订单机票信息列表
     */
    @PreAuthorize(hasPermi = "flight:tickets:export")
    @Log(title = "机票预订_机票退改签订单机票信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightOrderChangeTickets flightOrderChangeTickets) throws IOException
    {
        List<FlightOrderChangeTickets> list = flightOrderChangeTicketsService.selectFlightOrderChangeTicketsList(flightOrderChangeTickets);
        ExcelUtil<FlightOrderChangeTickets> util = new ExcelUtil<FlightOrderChangeTickets>(FlightOrderChangeTickets.class);
        util.exportExcel(response, list, "机票预订_机票退改签订单机票信息数据");
    }

    /**
     * 获取机票预订_机票退改签订单机票信息详细信息
     */
    @PreAuthorize(hasPermi = "flight:tickets:query")
    @GetMapping(value = "/{changeTicketId}")
    public AjaxResult getInfo(@PathVariable("changeTicketId") Long changeTicketId)
    {
        return AjaxResult.success(flightOrderChangeTicketsService.selectFlightOrderChangeTicketsById(changeTicketId));
    }

    /**
     * 新增机票预订_机票退改签订单机票信息
     */
    @PreAuthorize(hasPermi = "flight:tickets:add")
    @Log(title = "机票预订_机票退改签订单机票信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightOrderChangeTickets flightOrderChangeTickets)
    {
        return toAjax(flightOrderChangeTicketsService.insertFlightOrderChangeTickets(flightOrderChangeTickets));
    }

    /**
     * 修改机票预订_机票退改签订单机票信息
     */
    @PreAuthorize(hasPermi = "flight:tickets:edit")
    @Log(title = "机票预订_机票退改签订单机票信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightOrderChangeTickets flightOrderChangeTickets)
    {
        return toAjax(flightOrderChangeTicketsService.updateFlightOrderChangeTickets(flightOrderChangeTickets));
    }

    /**
     * 删除机票预订_机票退改签订单机票信息
     */
    @PreAuthorize(hasPermi = "flight:tickets:remove")
    @Log(title = "机票预订_机票退改签订单机票信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{changeTicketIds}")
    public AjaxResult remove(@PathVariable Long[] changeTicketIds)
    {
        return toAjax(flightOrderChangeTicketsService.deleteFlightOrderChangeTicketsByIds(changeTicketIds));
    }

    /**
     * 退票订单详情
     * @param map
     * @return
     */
    @PostMapping("/refundFlightOrder")
    public AjaxResult refundFlightOrder(@RequestBody Map<String, Object> map) {
        String orderId = String.valueOf(map.get("orderId"));
        List<FlightOrderChangeTickets> flightOrder = flightOrderChangeTicketsService.refundFlightOrder(orderId);
        return AjaxResult.success(flightOrder);
    }
}
